/*
 * @Author: your name
 * @Date: 2021-09-16 16:45:14
 * @LastEditTime: 2021-09-16 17:29:06
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \Briup\JS\lunbo\js\lunbo.js
 */
function $(id) {
    return document.getElementById(id);
}
window.onload = function() {
    var oLeft = $('left');
    var oRight = $('right');
    var index = 0;
    var timer = null;
    var pic = $('pic').getElementsByTagName("li");
    var num = $('num').getElementsByTagName('li');
    var odiv = $('wrap');

    // 用于图片切换的函数
    function change(curindex) {
        for (var i = 0; i < pic.length; i++) {
            pic[i].style.display = 'none';
            num[i].className = "";
        }
        pic[curindex].style.display = 'block';
        num[curindex].className = 'active';
        index = curindex;
    }

    // 小点点函数
    for (var i = 0; i < num.length; i++) {
        num[i].index = i;
        num[i].onmouseover = function() {
            change(this.index);
        }
    }
    //定时器函数
    function run() {
        index++;
        if (index >= pic.length)
            index = 0;
        change(index);
    }

    timer = setInterval(run, 2000);

    // 添加事件
    oLeft.onclick = function() {
        index--;
        if (index < 0) {
            index = pic.length - 1;
        }
        change(index);
    }
    oRight.onclick = function() {
        index++;
        if (index > pic.length - 1) {
            index = 0;
        }
        change(index);
    }
    odiv.onmouseout = function() {
        timer = setInterval(run, 2000);
    }
    odiv.onmouseover = function() {
        clearInterval(timer);
    }


}